/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package song;

import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

import java.util.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;

public class test {

    public static void main(String arge[]) {
        long lasting = System.currentTimeMillis();
        try {
            File f = new File("song.xml");
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(f);
            NodeList nl = doc.getElementsByTagName("topic");
           // String sql_insert = "";
           // String template = "INSERT INTO Persons (LastName, Address) VALUES ('Wilson', 'Champs-Elysees')";
            
            for (int i = 0; i < nl.getLength(); i++) {
                //String temp = "insert into supe_spaceitems ()";
                String temStr = "(";

                temStr =temStr + doc.getElementsByTagName("tid").item(i).getFirstChild().getNodeValue()+",";
                System.out.print("车牌号码:" + doc.getElementsByTagName("tid").item(i).getFirstChild().getNodeValue());
                System.out.println(" 车主地址:" + doc.getElementsByTagName("title").item(i).getFirstChild().getNodeValue());
                System.out.print("\n1:" + doc.getElementsByTagName("url").item(i).getFirstChild().getNodeValue());
                System.out.print("\n2:" + doc.getElementsByTagName("publisher").item(i).getFirstChild().getNodeValue());
                System.out.print("\n3:" + doc.getElementsByTagName("systemType").item(i).getFirstChild().getNodeValue());
                System.out.print("\n4:" + doc.getElementsByTagName("from").item(i).getFirstChild().getNodeValue());
               if(doc.getElementsByTagName("tag").item(i).getFirstChild()!=null) 
                System.out.print("\n5:" + doc.getElementsByTagName("tag").item(i).getFirstChild().getNodeValue());
                if(doc.getElementsByTagName("content").item(i).getFirstChild()!=null) 
                    System.out.print("\n6:" + doc.getElementsByTagName("content").item(i).getFirstChild().getNodeValue());
               if(doc.getElementsByTagName("image").item(i).getFirstChild()!=null) 
                   System.out.print("\n7:" + doc.getElementsByTagName("image").item(i).getFirstChild().getNodeValue());            
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("运行时间：" + (System.currentTimeMillis() - lasting) + " 毫秒");
        }
        System.out.println("运行时间：" + (System.currentTimeMillis() - lasting) + " 毫秒");
    }
}
